<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>页面</title>
</head>

<body>
    <script>
        //这样可以将script文件写在标签的前面
        window.onload = function() {
            var bt = document.querySelector('button');
            bt.addEventListener('click', function() {
                alert("点击了");
            })
        }
    </script>
    <!-- 页面加载事件用：window.load 整个页面的内容加载完后才会调用-->
    <button>点击</button>
    <!-- 这样只能在标签后面写 -->
    <!-- <script>
        var bt = document.querySelector('button');
        bt.addEventListener('click', function() {
            alert("点击了");
        })
    </script> -->

</body>

</html>